//
//  ZYZTabBarController.swift
//  MyWeiBo
//
//  Created by 牛牛很牛 on 15/12/15.
//  Copyright © 2015年 曾勇召. All rights reserved.
//

import UIKit

class ZYZTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        //自定义的TabBar是只读属性，不能直接赋值，用KVC进行替换
        let mainTabBar = ZYZMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        
        
        
        let homeVC = ZYZHomeController()
        self.addChildVC(homeVC, title: "首页", imageName: "tabbar_home")
        
        let messageVC = ZYZMessageController()
        self.addChildVC(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        let discoveryVC = ZYZDiscoveryController()
        self.addChildVC(discoveryVC, title: "发现", imageName: "tabbar_discover")
        
        let profileVC = ZYZProfileController()
        self.addChildVC(profileVC, title: "我", imageName: "tabbar_profile")
        

    }
    
    //添加TabBar的子控制器方法
    private func addChildVC(VC : UIViewController, title : String, imageName : String){
        //包装导航控制器
        self.addChildViewController(UINavigationController(rootViewController: VC))
        VC.title = title
        VC.tabBarItem.image = UIImage(named: imageName)
        
        //设置高亮图片,并忽略渲染效果
        let highlightedImageName = imageName + "_highlighted"
        VC.tabBarItem.selectedImage = UIImage(named: highlightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置文字颜色，效果要的是橘色
        VC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        
    }


}
